package com.ruoyi.web.controller.surfacewater;


import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.surfacewater.domain.LakeDataVo;
import com.ruoyi.surfacewater.service.NutritionalIndexService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/nutritionization")
public class NutritionizationController extends BaseController {

    @Autowired
    private NutritionalIndexService nutritionalIndexService;

    @PostMapping("/nutritionalAutoIndexlist")
    public Map nutritionalIndexlist(@RequestBody LakeDataVo vo) {
        Map map = new HashMap();//存放传入参数
        List<String> segmentIds = new ArrayList<>();
        if (vo.getSegmentId()!=null&&!"".equals(vo.getSegmentId())) {
            String[] arr = vo.getSegmentId().split(",");
            segmentIds = Arrays.asList(arr);
            map.put("SegmentIDs",segmentIds);
        }
        List<String> itemCodess = new ArrayList<>();
        if (vo.getItemCode()!=null&&!"".equals(vo.getItemCode())) {
            String[] arr = vo.getItemCode().split(",");
            itemCodess = Arrays.asList(arr);
            map.put("itemCodes",itemCodess);

        }

        map.put("startTime", vo.getBeginTime());
        map.put("endTime", vo.getEndTime());
        if(vo.getSegmentType()!=null&&!"".equals(vo.getSegmentType())){
            map.put("segmentType", vo.getSegmentType());
        }else {
            map.put("segmentType", "0");
        }
        //查询监测数据
        List<Map<String,Object>> list = nutritionalIndexService.nutritionalIndexlist(map);
        //没有办法调用工具和sql进行分页调用Java 对应方法进行分页查询
        Object collect = list.stream().skip((vo.getPageNum() - 1) * vo.getPageSize())
                .limit(vo.getPageSize())
                .collect(Collectors.toList());
        //获取总条数
        int size = list.size();
//返回数据结果集
        Map maplist = new HashMap();
        maplist.put("rows", collect);
        maplist.put("code", 200);
        maplist.put("msg", "查询成功");
        maplist.put("total", size);
        return maplist;
    }


    @PostMapping("/nutritionalManualIndexlist")
    public Map nutritionalStatusintlist(@RequestBody LakeDataVo vo) {

        Map map = new HashMap();//存放传入参数
        List<String> segmentIds = new ArrayList<>();
        if (vo.getSegmentId()!=null&&!"".equals(vo.getSegmentId())) {
            String[] arr = vo.getSegmentId().split(",");
            segmentIds = Arrays.asList(arr);
            map.put("SegmentIDs",segmentIds);
        }
        List<String> itemCodess = new ArrayList<>();
        if (vo.getItemCode()!=null&&!"".equals(vo.getItemCode())) {
            String[] arr = vo.getItemCode().split(",");
            itemCodess = Arrays.asList(arr);
            map.put("itemCodes",itemCodess);

        }


        map.put("startTime", vo.getBeginTime());
        map.put("endTime", vo.getEndTime());

        //查询监测数据
        List<Map<String,Object>> list = nutritionalIndexService.nutritionalStatusintlist(map);
        //没有办法调用工具和sql进行分页调用Java 对应方法进行分页查询
        Object collect = list.stream().skip((vo.getPageNum() - 1) * vo.getPageSize())
                .limit(vo.getPageSize())
                .collect(Collectors.toList());
        //获取总条数
        int size = list.size();
//返回数据结果集
        Map maplist = new HashMap();
        maplist.put("rows", collect);
        maplist.put("code", 200);
        maplist.put("msg", "查询成功");
        maplist.put("total", size);
        return maplist;
        // return AjaxResult.success(list);
    }

}
